package org.jeecg.modules.business.takestockplan.controller;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.jeecg.common.api.vo.Result;
import org.jeecg.common.system.query.QueryGenerator;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import lombok.extern.slf4j.Slf4j;

import org.jeecg.modules.business.takestockplan.entity.TakeStockResult;
import org.jeecg.modules.business.takestockplan.entity.VO.TakeStockPlanExecuteMaterialVO;
import org.jeecg.modules.business.takestockplan.entity.VO.TakeStockPlanExecuteVO;
import org.jeecg.modules.business.takestockplan.entity.VO.TakeStockResultMaterialVO;
import org.jeecg.modules.business.takestockplan.entity.VO.TakeStockResultVO;
import org.jeecg.modules.business.takestockplan.service.ITakeStockResultService;
import org.jeecg.common.system.base.controller.JeecgController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.jeecg.common.aspect.annotation.AutoLog;
import org.apache.shiro.authz.annotation.RequiresPermissions;

 /**
 * @Description: 盘盈盘亏单
 * @Author: jeecg-boot
 * @Date:   2023-08-08
 * @Version: V1.0
 */
@Api(tags="盘盈盘亏单")
@RestController
@RequestMapping("/business/takeStockResult")
@Slf4j
public class TakeStockResultController extends JeecgController<TakeStockResult, ITakeStockResultService> {
	@Autowired
	private ITakeStockResultService takeStockResultService;
	
	/**
	 * 分页列表查询
	 *
	 * @param takeStockResult
	 * @param pageNo
	 * @param pageSize
	 * @param req
	 * @return
	 */
	@ApiOperation(value="盘盈盘亏单-分页列表查询", notes="盘盈盘亏单-分页列表查询")
	@GetMapping(value = "/list")
	public Result<Page<TakeStockResultVO>> queryPageList(TakeStockResultVO takeStockResult,
														 @RequestParam(name="pageNo", defaultValue="1") Integer pageNo,
														 @RequestParam(name="pageSize", defaultValue="10") Integer pageSize,
														 HttpServletRequest req) {
		Result<Page<TakeStockResultVO>> result = new Result<>();
		Page<TakeStockResultVO> pageList = new Page<>(pageNo,pageSize);
		pageList = takeStockResultService.listByPage(pageList, takeStockResult);
		result.setSuccess(true);
		result.setResult(pageList);
		return result;
	}
	
	/**
	 *   通过id删除
	 *
	 * @param id
	 * @return
	 */
	@AutoLog(value = "盘盈盘亏单-通过id删除")
	@ApiOperation(value="盘盈盘亏单-通过id删除", notes="盘盈盘亏单-通过id删除")
	@RequiresPermissions("business:takeStockResult:delete")
	@DeleteMapping(value = "/delete")
	public Result<String> delete(@RequestParam(name="id",required=true) String id) {
		takeStockResultService.deleteResult(id);
		return Result.OK("删除成功!");
	}
	
	/**
	 * 通过id查询
	 *
	 * @param id
	 * @return
	 */
	@ApiOperation(value="盘盈盘亏单-通过id查询", notes="盘盈盘亏单-通过id查询")
	@GetMapping(value = "/queryById")
	public Result<List<TakeStockResultMaterialVO>> queryById(@RequestParam(name="id",required=true) String id) {
		TakeStockResultMaterialVO takeStockResult = takeStockResultService.getResultById(id);
		List<TakeStockResultMaterialVO> list = new ArrayList<>();
		list.add(takeStockResult);
		return Result.OK(list);
	}

	 /**
	  * 盘盈入库
	  *
	  * @param id
	  * @return
	  */
	 @ApiOperation(value="盘盈盘亏单-盘盈入库", notes="盘盈盘亏单-盘盈入库")
	 @PostMapping(value = "/addInReceipt")
	 public Result<String> addInReceipt(@RequestParam(name="id",required=true) String id) {
		 takeStockResultService.addInReceipt(id);
		 return Result.OK("盘盈入库成功");
	 }

	 /**
	  * 盘亏出库
	  *
	  * @param id
	  * @return
	  */
	 @ApiOperation(value="盘盈盘亏单-盘亏出库", notes="盘盈盘亏单-盘亏出库")
	 @PostMapping(value = "/addOutReceipt")
	 public Result<String> addOutReceipt(@RequestParam(name="id",required=true) String id) {
		 takeStockResultService.addOutReceipt(id);
		 return Result.OK("盘亏出库成功");
	 }

}
